package com.community.process._1010.controller;


import com.community.process._1010.common.api.CommonResult;
import com.community.process._1010.dao.view.ProcessCategoryNodeView;
import com.community.process._1010.dao.view.ProcessCategoryView;
import com.community.process._1010.domains.ProcessCategoryDTO;
import com.community.process._1010.service.ProcessCategoryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 到餐加工分类 前端控制器
 *
 * @author Zbs
 * @since 2024-09-05
 */
@RestController
@Tag(name = "到餐加工分类")
@RequestMapping("/process/category")
@RequiredArgsConstructor
public class ProcessCategoryController {

    private final ProcessCategoryService processCategoryService;

    @PostMapping("/addProcessCategory")
    @Operation(summary = "添加分类")
    public CommonResult<String> addProcessCategory(@RequestBody @Valid ProcessCategoryDTO.CategoryAdd dto) {
        this.processCategoryService.addProcessCategory(dto);
        return CommonResult.success("");
    }

    @PostMapping("/editProcessCategory")
    @Operation(summary = "编辑分类")
    public CommonResult<String> editProcessCategory(@RequestBody @Valid ProcessCategoryDTO.CategoryUpdate dto) {
        this.processCategoryService.editProcessCategory(dto);
        return CommonResult.success("");
    }

    @PostMapping("/deleteProcessCategory")
    @Operation(summary = "删除分类")
    public CommonResult<String> deleteProcessCategory(@RequestBody @Valid ProcessCategoryDTO.CategoryDelete dto) {
        this.processCategoryService.deleteProcessCategory(dto);
        return CommonResult.success("");
    }

    @PostMapping("/getProcessCategoryViewById/{id}")
    @Operation(summary = "获取类目详情")
    public CommonResult<ProcessCategoryView> getProcessCategoryViewById(@PathVariable Long id) {
        ProcessCategoryView view = this.processCategoryService.getProcessCategoryViewById(id);
        return CommonResult.success(view);
    }

    @PostMapping("/getPwItemCategoryList")
    @Operation(summary = "获取分类列表")
    public CommonResult<List<ProcessCategoryNodeView>> getPwItemCategoryList(@RequestBody @Valid ProcessCategoryDTO.CategoryPageSearch dto) {
        List<ProcessCategoryNodeView> view = this.processCategoryService.getPwItemCategoryList(dto);
        return CommonResult.success(view);
    }

    @PostMapping("/getPwItemCategoryNodeTree")
    @Operation(summary = "获取分类树")
    public CommonResult<List<ProcessCategoryNodeView>> getPwItemCategoryNodeTree(@RequestBody @Valid ProcessCategoryDTO.CategoryPageSearch dto) {
        List<ProcessCategoryNodeView> view = this.processCategoryService.getPwItemCategoryNodeTree(dto);
        return CommonResult.success(view);
    }

}

